<?php
Class C_index extends Cemvc_Control_Base
{
	public function index()
	{
	  if ($this->Role == ROLE_GUEST)
	    {
	      /* get user information from users table */
	      session_start();
	      if (!$_SESSION["openid"])
		{
		  if (isset($_REQUEST['openid']) && $_REQUEST['openid'])
		    $_SESSION["openid"] = $_REQUEST["openid"];
		  else
		    die("You must have an open id.");
		    
		  $_SESSION["openid"] = $_REQUEST["openid"];
		  $_SESSION["openkey"] = $_REQUEST['openkey'];
		  $_SESSION["pf"] = $_REQUEST["pf"];
		  $_SESSION["pfkey"] = $_REQUEST["pfkey"];
		}
	      
	      $Mdb=M_Qin_Users::getInstance();
	      $arr = $Mdb->where(array("qq_open_id = '".$_SESSION["openid"]."'"))->fetchOne();
	      if ($arr && isset($arr['id']))
	  	{
		  print "find @@@@@@@@@";
	  	  $this->setRole(ROLE_MEMBER);
	  	  session_start();
	  	  $_SESSION["id"] = $arr["id"];
	  	  $_SESSION["realname"] = $arr["realname"];
	  	  $_SESSION["gender"] = $arr["gender"];
	  	  $_SESSION["region_code"] = $arr["region_code"];
	  	  $_SESSION["day_of_birth"] = $arr["day_of_birth"];
	  	  $_SESSION["figureurl"] = $arr["figureurl"];
	  	  $_SESSION["creator"] = $arr["creator"];

	  	  $this->redirect("tree/index");
	  	  return;
	  	}
	      /* not found user information from the table */
	      /* this is the first time the user visit the site */
	      /* redirect to register page */
	      else
	  	{
		  print "not find @@@@@@@@@";
		  include_once "QinRegion.class.php";	  
		  $region = new QinRegion();
		  $prov_list = $region->getProvinceList();
		  include_once "QinUtility.class.php";
		  $this->assign("prov_list", QinUtility::make_options($prov_list));
	  	  $this->assign("WebTitle", "xxxxxxxxxxx");
	  	  $this->display();
	  	}
	    }
	  else if ($this->Role == ROLE_MEMBER)
	    {
	      $this->redirect("tree/index");
	    }
	  else if ($this->Role == ROLE_ADMIN)
	    {
	      $this->redirect("admin/index");
	    }
	}
	public function test()
	{
		echo 'test';
	}
}
//utf8编码
?>  
